package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.CrmTopicModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by lusong on 2016/11/11.
 */
public interface CrmTopicRepository extends JpaRepository<CrmTopicModel,Integer>,JpaSpecificationExecutor<CrmTopicModel> {

    @Query("select count(a.version) from CrmTopicModel a where a.permit = ?1 and a.version like ?2")
    int queryCurrentVersionNum(String permit, String dateString);

    @Query("select a from CrmTopicModel as a where a.permit = ?1 and a.stage = ?2 and a.version = ?3 order by a.id")
    List<CrmTopicModel> queryTopicByVersion(String permit, String stage, String version);

    @Query("select max(a.version) from CrmTopicModel as a where a.permit = ?1 and a.stage = ?2 and a.version like ?3")
    String queryMaxVersionByPermitAndSatge(String permit, String stage, String permitLike);

    @Query("select a from CrmTopicModel a where a.permit = ?1 and a.version = ?2 order by a.id")
    List<CrmTopicModel> findTopicByVersion(String permit, String version);
}
